package cn.ahaoweb.drule.core.compile.provide;

import cn.ahaoweb.drule.core.compile.enums.ConditionOperate;
import cn.ahaoweb.drule.core.compile.structure.DruleBlock;
import cn.ahaoweb.drule.core.model.info.TreeNode;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @Name: 可视化配置规则所需信息
 * @Description:   用于前端可视化配置
 * @Author: wangzhonghao
 * @Date: 2025/2/8 10:53
 */
@Data
public class VisualConfigInfo implements Serializable {

    // 规则分组
    private List<SelectItem> groups;

    // 规则集合
    private List<DruleBlock> rules;

    // 条件运算符
    private List<SelectItem> conditionOps;

    // 条件字段
    private ObjectTree conditionFields;

    // 结果字段
    private ObjectTree actionFields;

    public VisualConfigInfo(){
        this.rules = new ArrayList<>();
        this.conditionOps = new ArrayList<>();
        for (ConditionOperate conditionOperate : ConditionOperate.values()) {
            SelectItem of = SelectItem.of(conditionOperate.getLabel(), conditionOperate.name(), conditionOperate.getSymbol());
            this.conditionOps.add(of);
        }
    }

    public VisualConfigInfo(Class in, Class out){
        this();
        this.conditionFields = new ObjectTree(TreeNode.treeNode(in));
        this.actionFields = new ObjectTree(TreeNode.treeNode(out));
    }

}
